/**/

function loadXMLDoc(path){
	var xmlDoc=new ActiveXObject("MSXML.DOMDocument");
    xmlDoc.async="false";
    xmlDoc.load(path);
	return xmlDoc;
}
function bar(pct,tooltip){
   var barsDiv = document.getElementById("bars");
   barsDiv.innerHTML= barsDiv.innerHTML +'<table width="'+pct+'%" title="'+tooltip+'"><tr><td class="bar">'+pct+'%</td></tr></table>';
   return barsDiv;
}
function getRefreshRate(){
    //recalculate refresh rate
	var rate = document.getElementById("rate").value;
	return rate;
}
function monitor(){
	//alert(getRefreshRate());
	var barsDiv = document.getElementById("bars");
    barsDiv.innerHTML='';
	var response=loadXMLDoc("files/response.xml").documentElement;
	
    for (i=0;i < response.childNodes.length;i++){
		var output = response.childNodes(i);
		//who,what,uptime,percentage,time_remaining,operation
		var who = output.childNodes(0).childNodes(0).text;
		var program = output.childNodes(1).childNodes(0).text;
		var what = output.childNodes(2).childNodes(0).text;
		var uptime = output.childNodes(3).childNodes(0).text;	
		var percentage = output.childNodes(4).childNodes(0).text;
		var time_remaining = output.childNodes(5).childNodes(0).text;
		var operation = output.childNodes(6).childNodes(0).text;
        bar(percentage,'program: '+program+'&nbsp; what: '+what+'&nbsp; up time: '+uptime+'&nbsp; time remaining:'+time_remaining+'&nbsp; operation: '+operation);
    }
}

function init(){
    //window.prompt('reload');
    var oBackground = document.getElementById("imgBackground");
    oBackground.src = "url(img/bg.png)";
	
	var settings=loadXMLDoc("files/settings.xml").documentElement;
	var option = document.createElement("option");
    for (i=0;i < settings.childNodes.length;i++){
		var server = settings.childNodes(i).getAttribute("name");
		var serversCbo = document.getElementById("servers");
		var myOption = option.cloneNode(false);
		myOption.value = server;
		myOption.appendChild(document.createTextNode(server));
		serversCbo.appendChild(myOption);
	}
    System.Gadget.settingsUI = "settings.html";
	//recalculate refresh rate
	rate = getRefreshRate();
}
